<?php
require('../../../../lib/base.php');
$base=new base('web');
$session=$base->library('session',array('build'=>false));
if(!$session->ISSESS()){
	$helper=$base->library('helper');
	$helper->SMessage(5,domain.'view/Login.php?back='.domain.'home/module/system.php',"no","登陆失效,5秒后转到登陆页");
	exit();
}
$data['menu']=$base->cache(array('tag'=>'web.header','time'=>86400));
$data['menu']=unserialize($data['menu']);
$data['HomeMenu']=$base->cache(array('tag'=>'web.home.menu','time'=>86400));
$data['HomeMenu']=unserialize($data['HomeMenu']);
$data['foot']=$base->cache(array('tag'=>'web.footer','time'=>86400));
$mation=$base->model('information');
if($base->post('submit')){
	$data['message']=array('result'=>false,'msg'=>array());
	$data['account']=$base->post('account',true);
	$data['password']=$base->post('password',true);
	if(empty($data['account'])||empty($data['password'])){
		$data['message']['msg'][]='账户或密码不可为空.';
	}else{
		$check=$mation->GMation(array('where'=>array('account='=>$data['account'])));
		if(empty($check)){
			$config=$base->model('config');
			$outlet=$config->GConfig(array('where'=>array('label='=>'advertiser','name='=>'outlet')));
			$outlet=reset($outlet);$outlet=$outlet['value'];
			$http=$base->library('seo');
			$response=$http->httpRequest($outlet,null,array('account'=>$data['account'],'password'=>$data['password']));
			if(strtoupper($response['body'])=='YES'){
				$affected=$mation->UMation(array('where'=>array('member='=>intval($session->GVAR('member'))),'set'=>array('account='=>$data['account'])));
				if($affected==1){
					$data['message']['result']=true;
					$data['message']['msg'][]='账户绑定成功.';
				}else{
					$data['message']['msg'][]='请误重复提交.';
				}
			}else{
				if($response==false){
					$data['message']['msg'][]='验证接口连接失败.';
				}else{
					$data['message']['msg'][]=$response['body'];
				}
			}
		}else{
			$data['message']['msg'][]='你输入的账户已绑定.';
		}
	}
}
$data['account']=$mation->GMation(array('select'=>'account','where'=>array('member='=>intval($session->GVAR('member')))));
$data['account']=reset($data['account']);$data['account']=$data['account']['account'];
$base->set($data);
$base->view('home/module/outlet.php');
?>